package com.xinyuan.trade.Db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * @ brief <h3>该类是用来创建数据库的</h3>
 * 
 * <p>
 * 1、如果数据库不存在，创建数据库<br>
 * 2、如果数据库存在，就不创建<br>
 * 用来存取用户信息的users表<br>
 * 
 * @author 烨
 * 
 */
public class SqliteHelper extends SQLiteOpenHelper {
	// 订单
	public static final String TB_ORDER = "ds_order";
	//收货地址
	public static final String TB_ADDRESS = "ds_address";
    
	/**
	 * @param context
	 *            上下文context
	 * @param name
	 *            名称
	 * @param factory
	 *            CursorFactory
	 * @param version
	 *            版本号
	 */
	public SqliteHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);

	}

	/**
	 * @brief 该方法用来创建表
	 * @return 无
	 */
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("create table if not exists " + TB_ADDRESS + "("
				+ "address_id text primary key, " 
				+ "user_id text,"
				+ "consignee text,"
				+ "address text,"
				+ "tel text);");
		
		db.execSQL("create table if not exists " + TB_ORDER + "("
				+ "order_id text primary key, " 
				+ "order_sn text,"
				+ "order_status text,"
				+ "shipping_status text,"
				+ "pay_status text,"
				+ "add_time text,"
				+ "total_fee text,"
				+ "user_id text);");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// db.execSQL("DROP TABLE IF EXISTS " + TB_USER);
		// onCreate(db);
		Log.e("Database", "onUpgrade");
	}

}
